package com.simdo.g768.SQL;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DbHelper extends SQLiteOpenHelper {
    public static final String DATABASE_NAME = "data.db";
    public static final String HISTORY_TB = "history_tb";// 历史记录表
    private static final int DATABASE_VERSION = 2;

    public DbHelper(Context context){
        super(context,DATABASE_NAME,null,DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        // 类型有：Integer、text 文本、varchar (n)、real 浮点型、blob 二进制类型
        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS " + HISTORY_TB +
                "( _id INTEGER PRIMARY KEY AUTOINCREMENT," +
                "checked INTEGER," +
                "mode INTEGER," +
                "createTime varchar," +
                "startTime varchar," +
                "name varchar," +
                "config text" +
                ") ");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        if (oldVersion == 1) { // 由于之前1版本没有加name字段，这里新增
            // 添加新的列到已存在的表
            db.execSQL("ALTER TABLE history_tb ADD COLUMN name varchar");
        }
    }
}
